Sub HiddenSurroundRange()
Dim CelFirst As Range, CelLast As Range
    If Not Selection Is Nothing Then
        With Selection
            Set CelFirst = .Cells(1)
            Set CelLast = .Cells(.Cells.Count)
        End With
        If CelFirst.Address <> "$A$1" Then
            With Range([a1], CelFirst.Offset(IIf(CelFirst.Row = 1, 0, -1), IIf(CelFirst.Column = 1, 0, -1)))
                If CelFirst.Row <> 1 Then .EntireRow.Hidden = True
                If CelFirst.Column <> 1 Then .EntireColumn.Hidden = True
            End With
        End If
        If CelLast.Address <> "$IV$65536" Then
            With Range(CelLast.Offset(IIf(CelLast.Row = 65536, 0, 1), IIf(CelLast.Column = 256, 0, 1)), [IV65536])
                If CelLast.Row <> 65536 Then .EntireRow.Hidden = True
                If CelLast.Column <> 256 Then .EntireColumn.Hidden = True
            End With
        End If
    End If
End Sub
